import { _decorator, Component, Node } from 'cc';
import { Block } from './Block';
import { GAME_STATE_ENUM } from './Enum';
const { ccclass, property } = _decorator;

@ccclass('DataManager')
export class DataManager {
    private static _instance: any = null;

    static getInstance<T>(): T {
        if (this._instance !== null) {
            return this._instance;
        }

        return (this._instance = new this()) as T;
    }

    static get instance() {
        return this.getInstance<DataManager>();
    }

    private _level: number = 1; // 当前关卡
    blocks: Block[] = []; // 所有方块
    records: Block[] = []; // 放入槽里面的block
    currentLevel: LevelType = null; // 当前关卡数据 
    gameStatus: GAME_STATE_ENUM = GAME_STATE_ENUM.INIT; // 游戏状态,默认初始化
    clickable: boolean = false; // 是否可以点击, 使用明牌时通过该属性判断

    public get level(){
        return this._level;
    }  

    public set level(data: number){
        this._level = data;
        this.save()
    } 

    // 重置数据
    restart(){
        this.blocks = [];
        this.records = [];
        this.level = null;
        this.gameStatus = GAME_STATE_ENUM.INIT;
        this.clickable = false; 
    }

    // 保存数据
    save(){
        
    }

    //  读取（加载）数据
    restore(){
        
    }
} 

 